﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox2.Text = DateTime.Now.Year.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            // 清空结果文本框
            textBox3
        .Text = "";
            // 将起始年份和结束年份的字符串转换为 int 类型
            int startYear = int.Parse(textBox1.Text);
            int endYear = int.Parse(textBox2.Text);
            // 用于记录每行显示的闰年个数，方便对齐
            int count = 0;
            for (int i = startYear; i <= endYear; i++)
            {
                // 判断是否为闰年：能被 4 整除但不能被 100 整除，或者能被 400 整除
                if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
                {
                    // 将闰年添加到结果文本框，并用制表符 \t 对齐
                    textBox3
        .Text += i.ToString() + "\t";
                    count
        ++;
                    // 每行显示 5 个闰年，换行
                    if (count % 5 == 0)
                    {
                        textBox3
        .Text += Environment.NewLine;
                    }
                }
            }
        }
    }
}
